import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App.vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
import router from './router/index'
import store from './store/index.js'


import './assets/css/global.css';

Vue.prototype.$httpApi = axios
Vue.use(VueAxios, axios)
Vue.use(ElementUI)

axios.interceptors.request.use(
	config => {
		if (sessionStorage.getItem('token')) {
			config.headers.token = sessionStorage.getItem('token');
		}
		return config;
	},
	error => {
		return Promise.reject(error);
	});

// 导航守卫
// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
// router.beforeEach((to, from, next) => {
// 	let token = sessionStorage.getItem('token');
// 	console.log("token================" + token === null);
// 	if (to.name == 'Login') {
// 		next();
// 	}else {
// 		if (token === null || token === '') {
// 			console.log("token2================" + token === null);
// 			next({name:'Login'});
// 		} else {
// 			console.log("token3================" + token === null);
// 			next();
// 		}
// 	}
// });

new Vue({
	el: '#app',
	store,
	router,
	render: h => h(App)
})
